package com.chen;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

@SpringBootApplication
public class MyShardingSphereProxyDemoApplication {
    @Resource
    public DataSource dataSource;

    public static void main(String[] args) {
        SpringApplication.run(MyShardingSphereProxyDemoApplication.class, args);
    }

    @Bean
    public void myShardingSphereProxyTest() throws SQLException {
        String sql = "select * from t_order limit 0,10";
        Connection conn = dataSource.getConnection();
        Statement statement = conn.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        int colCount = resultSet.getMetaData().getColumnCount();
        for (int i = 1; i <= colCount; i++) {
            System.out.print(resultSet.getMetaData().getColumnLabel(i));
            System.out.print("\t");
        }
        System.out.println();
        while (resultSet.next()) {
            for (int i = 1; i <= colCount; i++) {
                System.out.print(resultSet.getObject(i));
                System.out.print("\t");
            }
            System.out.println();
        }
    }

}
